--推力测试 
import("System")
import("System.IO.Ports")
import("Jodell.Tool","Jodell.Tool")
--打开串口
client=Lua_ModbusRtuClient()
client.PortName="COM9"
client:Connect()

slave_ID1 = 9

--参数设置
ret = client:WriteUInt16(slave_ID1,1008,20000)
if ret ~= 0 then
	Error("设置1号设备使能失败")
	goto exit
end
ret = client:WriteUInt16(slave_ID1,1009,20000)
if ret ~= 0 then
	Error("设置1号设备使能失败")
	goto exit
end
ret = client:WriteUInt16(slave_ID1,1010,450)
if ret ~= 0 then
	Error("设置1号设备使能失败")
	goto exit
end
ret = client:WriteUInt16(slave_ID1,1011,200)
if ret ~= 0 then
	Error("设置1号设备使能失败")
	goto exit
end
ret = client:WriteUInt16(slave_ID1,1012,0)
if ret ~= 0 then
	Error("设置1号设备使能失败")
	goto exit
end
ret = client:WriteUInt16(slave_ID1,1013,5200)
if ret ~= 0 then
	Error("设置1号设备使能失败")
	goto exit
end
--设备使能
ret = client:WriteUInt16(slave_ID1,1002,1)
if ret ~= 0 then
	Error("设置1号设备使能失败")
	goto exit
end


while 1 do
	if (IsCancel) then
		Error("手动退出")
		goto exit
	end
	ret = client:WriteUInt16(slave_ID1,0x1003,1)
	if ret ~= 0 then
		Error("1号设备打开失败")
		goto exit
	end
	Delay(800)
	ret = client:WriteUInt16(slave_ID1,0x1003,0)
	if ret ~= 0 then
		Error("1号设备闭合失败")
		goto exit
	end
	Delay(800)
	
end

::exit:: 
client:Disconnect()
info("测试结束")